package com.ruoyi.baidu.service.impl;

import com.ruoyi.baidu.service.AnimalRepository;
import com.ruoyi.system.api.domain.AiExperiment;
import com.ruoyi.system.api.domain.AnimalInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnimalService {
    @Autowired
    private AnimalRepository animalRepository;
    @Value("${spring.elasticsearch.page}")
    private int page;
    @Value("${spring.elasticsearch.size}")
    private int size;

    public Iterable<AnimalInformation> findAll() {
        return animalRepository.findAll();
    }
    public void deleteAll() {
        animalRepository.deleteAll();
    }

    public AnimalInformation save(AnimalInformation animalInformation) {
        return animalRepository.save(animalInformation);
    }

    public List<AnimalInformation> search(String keyword) {
        Pageable pageable = PageRequest.of(page, size);
        return animalRepository.findBySpeciesNameOrBreedName(keyword, keyword, pageable).getContent();
    }
}
